module.exports = (root, opts) => {
  const { units } = opts;
  const covertRule = opts.rule[opts.platform].map(v => {
    const _s = v.split("2");
    return {
      key: _s[0],
      covert: _s[1]
    };
  });

  root.walkRules(postrule => {
    postrule.walkDecls(decl => {
      covertRule.forEach(v => {
        const _times = units[`${v.key}2${v.covert}`];
        const _regx = new RegExp(`([\\d\\.]+)${v.key}`);

        if (_regx.test(decl.value) && typeof _times === "number") {
          const _m = decl.value.match(_regx);
          decl.value = decl.value.replace(
            _m[0],
            `${_m[1] * _times}${v.covert}`
          );
        }
      });
      // PX to px
      if (/PX$/.test(decl.value)) {
        const _m = decl.value.match(/([\d\.]+)PX/);
        decl.value = decl.value.replace(_m[0], parseFloat(_m[1]) + "px");
      }
    });
    // 替换\:为_
    if (postrule.selector.includes("\\:")) {
      postrule.selectors = postrule.selectors.map(v => v.replace(/\\:/g, "_"));
    }
    // 替换:not(template) ~ :not(template) 为 * + *
    if (postrule.selector.includes(":not(template) ~ :not(template)")) {
      if (opts.alias.isWeixin.includes(opts.name)) {
        postrule.selector = postrule.selector.replace(
          ":not(template) ~ :not(template)",
          "view + view"
        );
      } else {
        postrule.selector = postrule.selector.replace(
          ":not(template) ~ :not(template)",
          "* + *"
        );
      }
    }
  });
};
